import { Button, Result } from 'antd';
import React, { useState, useEffect, useCallback } from 'react';
import { useHistory, useLocation } from 'react-router-dom';

const showTextArr = [
  {
    title: '访问被拒绝',
    subTitle: '您没有权限查看，请前往申请开通访问权限，以继续使用我们的服务。',
    btn: '申请开通权限',
  },
  {
    title: '正在审核中',
    subTitle: '您的申请已成功提交，我们会尽快完成审核，请耐心等待！',
    btn: '查看最新状态',
  },
  {},
  {
    title: '权限申请被驳回',
    subTitle: '您没有权限查看，请前往申请开通访问权限，以继续使用我们的服务。',
    btn: '重新申请开通权限',
  },
];

const NoSmsAuth: React.FC = () => {
  const history = useHistory();
  const location = useLocation();
  const queryParams = new URLSearchParams(location.search);
  const state = queryParams.get('state');

  /** 获取当前用户是否有对应权限 */
  const [showText, setShowText] = useState<any>(showTextArr[0]);
  const getIndustryAuth = useCallback(async () => {
    setShowText(showTextArr[+state] ?? {});
  }, [state]);

  useEffect(() => {
    getIndustryAuth();
  }, [getIndustryAuth]);

  return (
    <Result
      title={showText.title}
      subTitle={showText.subTitle}
      extra={
        <Button type="primary" onClick={() => history.push('/webapp/cas/abilities')}>
          {showText.btn}
        </Button>
      }
    />
  );
};

export default NoSmsAuth;
